'use strict';
let db = uniCloud.database()
exports.main = async (event, context) => {
	'use strict';
	const db = uniCloud.database();
	exports.main = async (event, context) => {
		//event为客户端上传的参数
		const {
			action
		} = event
		let res = {}
		if (action === 'get') {
			res = await db.collection('users').get()
		} else if (action === 'add') {
			const {
				name
			} = event
			res = await db.collection('users').add({
				name
			})
		} else if (action === 'delete') {
			const {
				id
			} = event
			res = await db.collection('users').doc(id).remove()
		} else if (action === 'getOne') {
			const {
				id
			} = event
			res = await db.collection('users').where({
				_id: id
			}).get()
		} else if (action === 'update') {
			const {
				form
			} = event
			res = await db.collection('users').where({
				_id: form._id
			}).update({
				name: form.name
			})
		}
	
		//返回数据给客户端
		return res
	};
	

	//  let users = await db.collection('uni-id-users').get();
	// return users
};
